﻿<UserControl 
    x:Class="FXSStation.Modules.Views.MainReportView.ReportModule.Views.MainReportView.MainReportView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:reports="clr-namespace:FXSStation.Modules.SharedInfrastructureModule.BusinessClasses.Reports;assembly=FXSStation.Modules.SharedInfrastructureModule"
    xmlns:converters="clr-namespace:FXSStation.Modules.SharedInfrastructureModule.Extentions.Converters;assembly=FXSStation.Modules.SharedInfrastructureModule"
    xmlns:reportView="clr-namespace:FXSStation.ReportModule.Views.ReportView"
    xmlns:igCA="http://infragistics.com/Chart"
    x:Name="ReportView">
    <UserControl.Resources>
        <converters:BuyOrdersConverter x:Key="BuyOrderConverter"/>
        <converters:SellOrdersConverter x:Key="SellOrderConverter"/>
        <converters:DataPointBackgroundConverter x:Key="backgroundConverter"/>
        <Style TargetType="{x:Type igCA:DataPoint}">
            <Setter Property="Fill" Value="{Binding Path=DataContext, RelativeSource={RelativeSource Self}, Converter={StaticResource backgroundConverter}}"/>
        </Style>
        <ItemsPanelTemplate x:Key="panelTemplate">
            <VirtualizingStackPanel Orientation="Vertical"/>
        </ItemsPanelTemplate>
        <DataTemplate DataType="{x:Type reports:Report}" x:Key="ReportTemplate" x:Shared="false">
            <Border CornerRadius="8,8,0,0" Margin="2" BorderBrush="Black" BorderThickness="1" Background="{DynamicResource TileViewPaneBackgroundSimple}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="0.2*"/>
                        <RowDefinition Height="0.6*"/>
                        <RowDefinition Height="0.2*"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <StackPanel HorizontalAlignment="Stretch" Width="Auto" Grid.Row="0" Grid.Column="0" 
                                VerticalAlignment="Stretch" Orientation="Horizontal">
                        <TextBlock Text="Report : "/>
                        <TextBlock Text="{Binding StartDate}"/>
                        <TextBlock Text="-"/>
                        <TextBlock Text="{Binding EndDate}"/>
                    </StackPanel>
                    <ListView IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Orders}" Background="Transparent"
                              Grid.Row="1" Grid.Column="0" >
                        <ListView.View>
                            <GridView ColumnHeaderContainerStyle="{DynamicResource ColumnHeaderContainerStyleBase}" ColumnHeaderTemplate="{DynamicResource ColumnHeaderTemplate}">
                                <GridViewColumn Header="TimeStamp" DisplayMemberBinding="{Binding TimeStamp}"/>
                                <GridViewColumn Header="IsClosed" DisplayMemberBinding="{Binding IsClosed}"/>
                                <GridViewColumn Header="CurrencySymbol" DisplayMemberBinding="{Binding CurrencySymbol}"/>
                                <GridViewColumn Header="Profit" DisplayMemberBinding="{Binding Profit}"/>
                                <GridViewColumn Header="Volume" DisplayMemberBinding="{Binding Volume}" Width="Auto"/>
                            </GridView>
                        </ListView.View>
                    </ListView>
                    <StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0" >
                        <TextBlock FontWeight="Bold" FontSize="14" Text="Profit : "/>
                        <TextBlock Text="{Binding Profit}"/>
                    </StackPanel>
                    
                    <Grid Grid.Row="0" Grid.RowSpan="3" Grid.Column="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <igCA:XamChart x:Name="reportChart"  Grid.Column="0"
                                   RefreshEnabled="True" DrawException="False">
                            <igCA:XamChart.Legend>
                                <igCA:Legend Visible="False"/>
                            </igCA:XamChart.Legend>
                            <igCA:XamChart.Series>
                                <igCA:Series DataSource="{Binding Orders}" ChartType="Bar" DataMapping="Value=Profit; Label=TimeStamp"/>
                            </igCA:XamChart.Series>
                            <igCA:XamChart.Axes>
                                <igCA:Axis AxisType="PrimaryX" AutoRange="True">
                                    <igCA:Axis.Label>
                                        <igCA:Label Format="{}{0:dd/MM/yyyy}" FontSize="18"/>
                                    </igCA:Axis.Label>
                                </igCA:Axis>
                                <igCA:Axis AxisType="PrimaryY" AutoRange="True">
                                    <igCA:Axis.Label>
                                        <igCA:Label Format="{}{0:c}" Angle="0" FontSize="18"/>
                                    </igCA:Axis.Label>
                                </igCA:Axis>
                            </igCA:XamChart.Axes>
                        </igCA:XamChart>
                        
                        <UniformGrid x:Name="legend" Columns="2" Grid.Column="1" VerticalAlignment="Center">
                            <Rectangle Width="20" Height="20" Fill="Blue"/>
                            <TextBlock Text="Buy Order" VerticalAlignment="Center"/>
                            <Rectangle Width="20" Height="20" Fill="Red"/>
                            <TextBlock Text="Sell Order" VerticalAlignment="Center"/>
                        </UniformGrid>
                        
                    </Grid>
                </Grid>

            </Border>
        </DataTemplate>
        <DataTemplate x:Key="ComparisonReportTemplate" DataType="{x:Type reports:ComparisonReport}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <ComboBox x:Name="primaryAccout" Grid.Row="0" Grid.Column="0" 
                          ItemsSource="{Binding AvailableAccounts}" DisplayMemberPath="Name" SelectedItem="{Binding Account}"/>
                <ComboBox x:Name="secondaryAccount" Grid.Row="0" Grid.Column="1" 
                          ItemsSource="{Binding AvailableAccounts}" DisplayMemberPath="Name" SelectedItem="{Binding SecondaryAccount}"/>
                <ItemsControl ItemTemplate="{StaticResource ReportTemplate}" ItemsPanel="{StaticResource panelTemplate}"
                              ItemsSource="{Binding PrimaryReports}" 
                              Grid.Column="0" Grid.Row="1"/>
                <ItemsControl ItemTemplate="{StaticResource ReportTemplate}" ItemsPanel="{StaticResource panelTemplate}"
                              ItemsSource="{Binding SecondaryReports}" 
                              Grid.Column="1" Grid.Row="1"/>
            </Grid>
        </DataTemplate>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TabControl Grid.Row="1" x:Name="reportsControl">
            <TabItem Header="Session Report" Content="{Binding SessionReport}">
                <TabItem.ContentTemplate>
                    <StaticResource ResourceKey="ReportTemplate"/>
                </TabItem.ContentTemplate>
            </TabItem>
            <TabItem Header="Account Report" Content="{Binding AccountReport}">
                <TabItem.ContentTemplate>
                    <DataTemplate>
                        <ItemsControl ItemsSource="{Binding}">
                            <ItemsControl.ItemTemplate>
                                <StaticResource ResourceKey="ReportTemplate"/>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </DataTemplate>
                </TabItem.ContentTemplate>
            </TabItem>
            <TabItem Header="Comparison Report" Content="{Binding ComparisonReport}">
                <TabItem.ContentTemplate>
                    <StaticResource ResourceKey="ComparisonReportTemplate"/>
                </TabItem.ContentTemplate>
            </TabItem>
        </TabControl>
    </Grid>
</UserControl>
